# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import APIRouter, Depends
from hypertext import R, PagingResult, response_json
from apps.admin.schemas.users import user_schema as schema
from apps.admin.service.users.user_service import UserService

router = APIRouter(prefix="/user", tags=["用户管理"])


@router.get("/sessions", summary="会话列表", response_model=R[PagingResult[schema.UserSessionListVo]])
@response_json
async def sessions(params: schema.UserSessionIn = Depends()):
    return await UserService.sessions(params)


@router.get("/lists", summary="用户列表", response_model=R[schema.UserListVo])
@response_json
async def lists(params: schema.UserSearchIn = Depends()):
    return await UserService.lists(params)


@router.get("/detail", summary="用户详情", response_model=R[schema.UserDetailVo])
@response_json
async def detail(params: schema.UserDetailIn = Depends()):
    return await UserService.detail(params.id)


@router.get("/subscribe", summary="用户订阅", response_model=R[schema.UserSubscribeVo])
@response_json
async def subscribe(params: schema.UserDetailIn = Depends()):
    return await UserService.subscribe(params.id)


@router.post("/create", summary="用户创建", response_model=R)
@response_json
async def create(params: schema.UserCreateIn):
    return await UserService.create(params)


@router.post("/edit", summary="用户编辑", response_model=R)
@response_json
async def edit(params: schema.UserEditIn):
    return await UserService.edit(
        params.user_id,
        params.field,
        params.value
    )


@router.post("/blacklist", summary="拉黑名单", response_model=R)
@response_json
async def blacklist(params: schema.UserIdIn):
    return await UserService.blacklist(params.user_id)


@router.post("/change_group", summary="修改分组", response_model=R)
@response_json
async def change_group(params: schema.UserChangeGroupIn):
    return await UserService.change_group(
        params.user_id,
        params.group_id
    )


@router.post("/reset_password", summary="重置密码", response_model=R)
@response_json
async def reset_password(params: schema.UserResetPasswordIn):
    return await UserService.reset_password(
        params.user_id,
        params.password
    )


@router.post("/adjust_account", summary="调整账户", response_model=R)
@response_json
async def adjust_account(params: schema.UserAdjustAccountIn):
    return await UserService.adjust_account(
        params.user_id,
        params.scene,
        params.action,
        int(params.amount)
    )


@router.post("/kick_out", summary="强制下线", response_model=R)
@response_json
async def kick_out(params: schema.UserKickOutIn):
    return await UserService.kick_out(
        params.user_id,
        params.uuid
    )
